#dirsize.sh
#2012 M.J. Gardner
#print directory and subdirectory names and sizes, along with lists of files and their sizes

PREFIX=""

function dir_siz {
	DIRNAME=`pwd`
	OUT=`du -h -s "${DIRNAME}" `
	echo "${PREFIX}${OUT}"

	PREFIX="${PREFIX}	"

	if [ ! -z "$(ls)" ]
	then
		for i in *
		do
			if [ ! -d "${i}" ]
			then
				OUT=`du -h "${i}" `
				echo "${PREFIX}${OUT}"
			fi
		done
	fi
	echo -e ""
	for i in *
	do
		if [ -d "${i}" ]
		then
			cd "${i}"
			dir_siz
			PREFIX=${PREFIX:1}
			cd ..
		fi
	done
}

dir_siz
